package org.lx.nursing.controller.member;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.lx.common.annotation.Log;
import org.lx.common.core.controller.BaseController;
import org.lx.common.core.domain.AjaxResult;
import org.lx.common.core.domain.R;
import org.lx.common.enums.BusinessType;
import org.lx.nursing.domain.FamilyMember;
import org.lx.nursing.dto.ElderInfoDTO;
import org.lx.nursing.dto.UserLoginRequestDto;
import org.lx.nursing.service.IFamilyMemberService;
import org.lx.nursing.vo.ElderFamilyBindVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 老人家属Controller
 *
 * @author sewen
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "C端-老人家属相关接口")
@Slf4j
public class FamilyMemberController extends BaseController {
    @Resource
    private IFamilyMemberService familyMemberService;

    /**
     * 小程序登录
     */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        return success(familyMemberService.login(dto));
    }


    /**
     * 1.1 绑定家人
     * 接口地址:/member/user/add
     * 请求方式:POST
     */
    @PostMapping("/add")
    public AjaxResult bindElder(@RequestBody ElderInfoDTO dto) {
        log.info("-----绑定家人信息:{}", dto);
        boolean result = familyMemberService.bindElder(dto);
        if (result) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

    //1.2 查询家人列表
    //    接口地址:/member/user/my
    //    请求方式:GET
    @PreAuthorize("@ss.hasPermi('nursing:FamilyMember:list')")
    //@GetMapping("/my")
    @ApiOperation("查询老人家属列表")
    public AjaxResult getMyFamilyMember() {
        return success(familyMemberService.getMyFamilyMember());
    }

    /**
     * 1.3 查看家人列表（分页查询）
     * 接口地址:/member/user/list-by-page
     * 请求方式:GET
     */
    @GetMapping("/list-by-page")
    public AjaxResult listByPage(Integer pageNum, Integer pageSize) {
        List<ElderFamilyBindVO> list = familyMemberService.listByPage(pageNum, pageSize);
        return AjaxResult.success(list);
    }


    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable String iotId) {
        return success(familyMemberService.queryServiceProperties(iotId));
    }

    /**
     * 1.5 按天统计查询指标数据
     * 接口地址:/member/user/queryDeviceDataListByDay
     * 请求方式:GET
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(String iotId, String functionId, Long startTime, Long endTime) {
        return success(familyMemberService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime));
    }

    /**
     * 1.6 按周统计查询指标数据
     * 接口地址:/member/user/queryDeviceDataListByWeek
     * 请求方式:GET
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(String iotId, String functionId, Long startTime, Long endTime) {
        return success(familyMemberService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime));
    }

}
